﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using System.Text;
	using System.Runtime.Serialization;

	/// <summary>
	/// A Data Transfer Object (DTO) that represents a user 
	/// from twitter.
	/// </summary>
	/// <remarks>
	///		<para>
	///			It represents the &quot;user&quot; element/object in both the xml and 
	///			json portions of the REST responses. 
	///		</para>
	/// </remarks>
	[DataContract(Name="user")]
	public class User : TwitterError 
	{
		private string createdAtString = "";
		private DateTime createdAt = DateTime.MinValue;

		/// <summary>
		/// Gets or sets the unique id of the user.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="id")]
		public int Id { get; set; }

		/// <summary>
		/// Gets or sets the name of the user.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;name&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="name")]
		public string Name { get; set; }

		/// <summary>
		/// Gets or sets the screen name of the user.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;screen_name&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "screen_name")]
		public string Screename { get; set; }

		/// <summary>
		///	Gets or sets the location of the user.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;id&quot;.
		///			This can be any string as this is currently not a geo code or anything that
		///			is terribly specific.
		///		</para>
		/// </remarks>
		[DataMember(Name="location")] 
		public string location { get; set; }

		/// <summary>
		/// Gets or sets the user's description.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;description&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "description")]
		public string Description { get; set; }

		/// <summary>
		/// Gets or sets the user's profile image url.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;profile_image_url&quot;. The 
		///			url is an image found on the web.
		///		</para>
		/// </remarks>
		[DataMember(Name = "profile_image_url")]
		public string ProfileImageUrl { get; set; }

		/// <summary>
		/// Gets or sets the user's url, which can be any url the user specifies.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;url&quot;.
		///			This can be null. 
		///		</para>
		/// </remarks>
		[DataMember(Name = "url")]
		public string Url { get; set; }

		/// <summary>
		/// Gets or sets the flag to determine if the user's profile is protected.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;protected&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "protected")]
		public bool IsProtected { get; set; }

		/// <summary>
		/// Gets or sets the number of followers the user has.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;followers_count&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "followers_count")]
		public int? FollowersCount { get; set; }

		/// <summary>
		/// Gets or sets the current <see cref="Amplify.Twitter.Status"/>/tweet/message of the user.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;status&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "status")]
		public Status Status { get; set; }

		/// <summary>
		/// Gets or sets the user's profile background color. (Css Hex Value)
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;profile_background_color&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "profile_background_color")]
		public string ProfileBackgroundColor { get; set; }

		/// <summary>
		/// Gets or sets the user's profile text color. (Css Hex Value)
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;profile_text_color&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "profile_text_color")]
		public string ProfileTextColor { get; set; }

		/// <summary>
		/// Gets or sets the user's profile link color. (Css Hex Value)
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;profile_link_color&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "profile_link_color")]
		public string ProfileLinkColor { get; set; }

		/// <summary>
		/// Gets or sets the user's profile sidebar fill color. (Css Hex Value)
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;profile_sidebar_fill_color&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "profile_sidebar_fill_color")]
		public string ProfileSidebarFillColor { get; set; }


		/// <summary>
		/// Gets or sets the user's profile sidebar border color. (Css Hex Value)
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;profile_sidebar_border_color&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "profile_sidebar_border_color")]
		public string ProfileSidebarBorderColor { get; set; }

		/// <summary>
		/// Gets or sets <see cref="System.String"/> value of the Date/Time the user was created.
		/// </summary>
		/// <remarks>
		///		<para>
		///		The string format from twitter is &quot;ddd MMM dd HH:mm:ss zzzz yyyy&quot;
		///		</para>
		/// </remarks>
		[DataMember(Name = "created_at")]
		public string CreatedAtString {
			get { return this.createdAtString; }
			set {
				this.createdAtString = value;
				if (!string.IsNullOrEmpty(value))
				{
					this.createdAt = DateTime.ParseExact(
						value, Status.TimeFormat,
						 CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
				}
			}
		}

		/// <summary>
		/// Gets or sets <see cref="System.DateTime"/> value of the created_at value from  
		/// twitter, if it can be parsed. 
		/// </summary>
		public DateTime CreatedAt
		{
			get { return this.createdAt; }
			set
			{
				this.createdAt = value;
				this.createdAtString = value.ToString(Status.TimeFormat);
			}
		}


		/// <summary>
		/// Gets or sets the user's friends count.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;friends_count&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "friends_count")]
		public int? FriendsCount { get; set; }

		/// <summary>
		/// Gets or sets the user's favorites count.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;favorites_count&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "favorites_count")]
		public int? FavoritesCount { get; set; }

		/// <summary>
		/// Gets or sets the user's utc offset value, i.e. -18000.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;utf_offset&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "utc_offset")]
		public int? UtcOffset { get; set; }

		/// <summary>
		/// Gets or sets the user's time zone value, i.e. &quot;>Eastern Time (US &amp; Canada)&quot;
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;time_zone&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "time_zone")]
		public string TimeZone { get; set; }

		/// <summary>
		/// Gets or sets the flag that determines if the user is following other users.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;following&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "following")]
		public bool? IsFollowing { get; set; }

		/// <summary>
		/// Gets or sets the flag that determines if the user has notifications.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;notifications&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "notifications")]
		public bool? HasNotifications { get; set; }

		/// <summary>
		/// Gets or sets the user's number of <see cref="Amplify.Twitter.Status"/>/tweets/messages.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;statuses_count&quot;.
		///			This is only available when twitter sends back a user with extended 
		///			information.
		///		</para>
		/// </remarks>
		[DataMember(Name = "statuses_count")]
		public int? StatusesCount { get; set; }
	}
}
